home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / windows / fonts / showfixw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  5.9 KB  |  219 lines

  1. /***                                                  ***/
  2. /***  a test program for changing the fonts           ***/
  3. /***                                                  ***/
  4. /***  This will display the fonts that can be used    ***/
  5. /***  in dvtools programs. It will show the           ***/
  6. /***  information needed for the DV.INI file          ***/
  7. /***                                                  ***/
  8.  
  9. #include <windows.h>
  10. #include "std.h"
  11. #include "dvtools.h"
  12. #include "dvstd.h"
  13. #include "Tfundecl.h"
  14. #include "GRfundecl.h"
  15. #include "dvGR.h"
  16.  
  17. int  CALLBACK getnumfaces();
  18. int  CALLBACK getfacenames();
  19. int  CALLBACK draw_it();
  20. void          show_fonts();
  21.  
  22. struct face_struct
  23.        {
  24.          int    num_faces;    /* total num of faces on system */
  25.          int    face_to_fill; /* index int face_names array */
  26.          char **face_names;
  27.          int    width;
  28.         } ;
  29.  
  30. HDC   bigboy;
  31.  
  32. int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  33.                      LPSTR lpCmdLine, int nCmdShow)
  34. {
  35.   OBJECT      screen;
  36.   VIEW        view;
  37.   DRAWPORT    drawport;
  38.   long        window_height;
  39.   long        window_width;
  40.  
  41.   int         argc;   /* number of args */
  42.   char      **argv;   /* command line args- unix style */
  43.  
  44.   /* this call makes the unix style argv */
  45.   /* it's just here for demo only */
  46.   make_argv(&argc,&argv,GetCommandLine());
  47.  
  48.   window_height = 480;
  49.   window_width  = 640;
  50.  
  51.   /* you always have to do this to use our stuff */
  52.   TInit(NULL,NULL);
  53.  
  54.   screen = TscOpenSet("W", NULL, V_WINDOW_X, 0,
  55.                        V_WINDOW_Y, 0, V_WINDOW_WIDTH, window_width,
  56.                        V_WINDOW_HEIGHT, window_height, V_END_OF_LIST);
  57.  
  58.   if ( screen == (OBJECT) NULL )
  59.   {
  60.     /* could not open a window, die die die */
  61.     exit( -1 );
  62.   }
  63.  
  64.   view = TviCreate();
  65.  
  66.   drawport = TdpCreateStretch( screen, view, NULL, NULL );
  67.  
  68.  
  69.   show_fonts();
  70.  
  71.   /* Sleep will not work very well on win32s */
  72.   Sleep(2000);
  73.  
  74.   TdpDestroy(drawport);
  75.   TviDestroy(view);
  76.   TscCloseCurrentScreen();
  77.   TTerminate();
  78.   return(1);
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /***                                                      ***/
  87. /***   This file shows how to change fonts in a DataViews ***/
  88. /***   program running on Windows NT. This done by using  ***/
  89. /***   GRget and GRset.  GRget is used to get the window  ***/
  90. /***   handle for the current device. That handle is then ***/
  91. /***   used to find what fonts are available. The current ***/
  92. /***   font used by DataViews is then changed using GRset.***/
  93.  
  94. void show_fonts()
  95. {
  96.   struct face_struct  faces;
  97.          int          x;
  98.          HDC          hdc;
  99.          HWND         win_handle;
  100.  
  101.  
  102.   /*  This call will get the window handle used by the */
  103.   /*  DataViews driver for the current device */
  104.   GRget(V_WIN32_WINDOW_HANDLE,&win_handle,V_END_OF_LIST);
  105.  
  106.   /* This win32 call will get the handle to the display */
  107.   /* context for the window handle*/
  108.   hdc = GetDC(win_handle);
  109.   bigboy = hdc;
  110.   faces.num_faces = 0;
  111.   /* This win32 call will get the number of font faces */
  112.   /* that are available */
  113.   EnumFonts(hdc,NULL,getnumfaces,(LPARAM)&(faces.num_faces));
  114.  
  115.   faces.face_names = ( char **) malloc(
  116.                       sizeof(char *) * faces.num_faces);
  117.   faces.face_to_fill = 0;
  118.  
  119.   /* This win32 call will get the names of all the faces */
  120.   EnumFonts(hdc,NULL,getfacenames,(LPARAM)&faces);
  121.  
  122.  
  123.   for( x = 0;  x < faces.num_faces ;  x++)
  124.   {
  125.     /* for each face, look at all the fonts in that face */
  126.     EnumFonts(hdc,faces.face_names[x],draw_it,(LPARAM)&faces);
  127.  
  128.   }
  129.  
  130.   ReleaseDC(win_handle,hdc);
  131. }
  132.  
  133.  
  134. /** this function is used with EnumFonts to find out how many **/
  135. /** font faces exist on the current device                    **/
  136. int CALLBACK getnumfaces(LOGFONT *log_font, TEXTMETRIC *text_metric,
  137.                        DWORD font_type,int * param)
  138. {
  139.  
  140.   (*param)++;
  141.   return(1);
  142. }
  143.  
  144. /** this function is used with EnumFonts to get the name of each **/
  145. /** font face                                                    **/
  146. int CALLBACK getfacenames(LOGFONT *log_font, TEXTMETRIC *text_metric,
  147.                        DWORD font_type,struct face_struct *param)
  148. {
  149.   int len;
  150.  
  151.   len = strlen(log_font->lfFaceName);
  152.   len++;
  153.   param->face_names[param->face_to_fill] = (char *)malloc(len);
  154.   strcpy(param->face_names[param->face_to_fill],log_font->lfFaceName);
  155.   (param->face_to_fill)++;
  156.  
  157.   return(1);
  158. }
  159.  
  160.  
  161. int CALLBACK draw_it(LOGFONT *log_font, TEXTMETRIC *text_metric,
  162.                   DWORD font_type,struct face_struct *param)
  163. {
  164.   HFONT      this_font = 0;
  165.   DV_POINT   p;
  166.   char       mess[64];
  167.   int        x,y;
  168.   SIZE       size;
  169.  
  170.   /* Most DataViews character display routines must have */
  171.   /* fixed width fonts.  So show only fixed width fonts. */
  172.   if ( text_metric->tmAveCharWidth == text_metric->tmMaxCharWidth)
  173.   {
  174.     this_font = CreateFontIndirect(log_font);
  175.     if ( this_font != 0 )
  176.     {
  177.  
  178.       GRerase();
  179.  
  180.       /* this call to GRset is the one that changes one of the */
  181.       /* DataViews hardware fonts to your choice of a font.    */
  182.       /* the argument "1" is the index of the font you want    */
  183.       /* changed. the next argumant, "this_font", is a HFONT   */
  184.       /* created by the CreateFontIndirect() win32 API function*/
  185.       GRset(V_WIN32_NEWFONT,1,this_font,V_END_OF_LIST);
  186.  
  187.       /* This call makes the DataViews driver use index 1 as the */
  188.       /* current font */
  189.       GRch_size(1,1);
  190.  
  191.       /* this loop draws a text string to the window using */
  192.       /* the current font */
  193.       p.y = 200;
  194.       {
  195.         int b;
  196.  
  197.         GetTextExtentPoint(bigboy,"M",1,&size);
  198.         sprintf(mess,"name=%s   x=%d y=%d ",log_font->lfFaceName,
  199.                   size.cx,size.cy);
  200.         for( b = 630; b > 0 ; b--)
  201.         {
  202.           p.x = b;
  203.           GRmove(&p);   
  204.           GRtext(mess);
  205.           GRflush();
  206.         }
  207.       }
  208.       Sleep(700);
  209.  
  210.     }
  211.  
  212.   }
  213.   return( TRUE);
  214. }
  215.  
  216.  
  217.  
  218.  
  219.